<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Denzel - SVG轻松实现路径动画</title>
    <meta name="description" content="前端笔记">
    <meta name="keywords" content="web前端,HTML5,CSS3,Javascript,SVG,canvas">
  <meta name="anthor" content="Denzel">
  <meta name="theme-color" content="#3eaf7c">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="msapplication-TileImage" content="/icons/msapplication-icon-144x144.png">
  <meta name="msapplication-TileColor" content="#000000">
  <link rel="icon" href="/blog/vuepress/logo.png">
  <link rel="manifest" href="/blog/vuepress/manifest.json">
  <link rel="apple-touch-icon" href="/blog/vuepress/icons/apple-touch-icon-152x152.png">
  <link rel="mask-icon" href="/blog/vuepress/icons/safari-pinned-tab.svg" color="#3eaf7c">
    
    <link rel="preload" href="/blog/vuepress/assets/css/0.styles.d4f29607.css" as="style"><link rel="preload" href="/blog/vuepress/assets/js/app.15770e34.js" as="script"><link rel="preload" href="/blog/vuepress/assets/js/48.e0bf8b54.js" as="script"><link rel="preload" href="/blog/vuepress/assets/js/63.9ac2b61d.js" as="script"><link rel="preload" href="/blog/vuepress/assets/js/65.923a8d15.js" as="script"><link rel="preload" href="/blog/vuepress/assets/js/72.f1c4098c.js" as="script"><link rel="prefetch" href="/blog/vuepress/assets/js/46.59c0ece7.js"><link rel="prefetch" href="/blog/vuepress/assets/js/1.05e4270f.js"><link rel="prefetch" href="/blog/vuepress/assets/js/2.ace739f7.js"><link rel="prefetch" href="/blog/vuepress/assets/js/3.636e5a79.js"><link rel="prefetch" href="/blog/vuepress/assets/js/4.7a55aa4b.js"><link rel="prefetch" href="/blog/vuepress/assets/js/5.b56b0573.js"><link rel="prefetch" href="/blog/vuepress/assets/js/6.e9a3fbc8.js"><link rel="prefetch" href="/blog/vuepress/assets/js/7.aa46c47d.js"><link rel="prefetch" href="/blog/vuepress/assets/js/8.a9288ac6.js"><link rel="prefetch" href="/blog/vuepress/assets/js/9.b9f8dec6.js"><link rel="prefetch" href="/blog/vuepress/assets/js/10.3e2ea470.js"><link rel="prefetch" href="/blog/vuepress/assets/js/11.4d115f98.js"><link rel="prefetch" href="/blog/vuepress/assets/js/12.c97cf4d0.js"><link rel="prefetch" href="/blog/vuepress/assets/js/13.1e0cf594.js"><link rel="prefetch" href="/blog/vuepress/assets/js/14.bab9026a.js"><link rel="prefetch" href="/blog/vuepress/assets/js/15.1a24cffe.js"><link rel="prefetch" href="/blog/vuepress/assets/js/16.e9995850.js"><link rel="prefetch" href="/blog/vuepress/assets/js/17.86a1f7d2.js"><link rel="prefetch" href="/blog/vuepress/assets/js/18.c32400c4.js"><link rel="prefetch" href="/blog/vuepress/assets/js/19.9f99887c.js"><link rel="prefetch" href="/blog/vuepress/assets/js/20.82f0c2f9.js"><link rel="prefetch" href="/blog/vuepress/assets/js/21.7f5c223d.js"><link rel="prefetch" href="/blog/vuepress/assets/js/22.acf9934c.js"><link rel="prefetch" href="/blog/vuepress/assets/js/23.20d8e817.js"><link rel="prefetch" href="/blog/vuepress/assets/js/24.acf27379.js"><link rel="prefetch" href="/blog/vuepress/assets/js/25.20165510.js"><link rel="prefetch" href="/blog/vuepress/assets/js/26.83a2ddc3.js"><link rel="prefetch" href="/blog/vuepress/assets/js/27.33276a04.js"><link rel="prefetch" href="/blog/vuepress/assets/js/28.e320efab.js"><link rel="prefetch" href="/blog/vuepress/assets/js/29.3fd92c30.js"><link rel="prefetch" href="/blog/vuepress/assets/js/30.2bc84d43.js"><link rel="prefetch" href="/blog/vuepress/assets/js/31.d70ed500.js"><link rel="prefetch" href="/blog/vuepress/assets/js/32.e7a0f8e1.js"><link rel="prefetch" href="/blog/vuepress/assets/js/33.c48ee70b.js"><link rel="prefetch" href="/blog/vuepress/assets/js/34.8ad03d1b.js"><link rel="prefetch" href="/blog/vuepress/assets/js/35.5bdb3994.js"><link rel="prefetch" href="/blog/vuepress/assets/js/36.a25f926e.js"><link rel="prefetch" href="/blog/vuepress/assets/js/37.7515cfbb.js"><link rel="prefetch" href="/blog/vuepress/assets/js/38.99347371.js"><link rel="prefetch" href="/blog/vuepress/assets/js/39.3481fc62.js"><link rel="prefetch" href="/blog/vuepress/assets/js/40.bc709734.js"><link rel="prefetch" href="/blog/vuepress/assets/js/41.e1e0a3bf.js"><link rel="prefetch" href="/blog/vuepress/assets/js/42.762b61b0.js"><link rel="prefetch" href="/blog/vuepress/assets/js/43.8f0b2d6c.js"><link rel="prefetch" href="/blog/vuepress/assets/js/44.2a0a4ee0.js"><link rel="prefetch" href="/blog/vuepress/assets/js/45.baf7ed60.js"><link rel="prefetch" href="/blog/vuepress/assets/js/47.11a8720a.js"><link rel="prefetch" href="/blog/vuepress/assets/js/49.c96c4011.js"><link rel="prefetch" href="/blog/vuepress/assets/js/50.31189263.js"><link rel="prefetch" href="/blog/vuepress/assets/js/51.766a8294.js"><link rel="prefetch" href="/blog/vuepress/assets/js/52.26b971fd.js"><link rel="prefetch" href="/blog/vuepress/assets/js/53.0cfbd708.js"><link rel="prefetch" href="/blog/vuepress/assets/js/54.bdc15c87.js"><link rel="prefetch" href="/blog/vuepress/assets/js/55.fea285a9.js"><link rel="prefetch" href="/blog/vuepress/assets/js/56.e030a6b2.js"><link rel="prefetch" href="/blog/vuepress/assets/js/57.bd168a1e.js"><link rel="prefetch" href="/blog/vuepress/assets/js/58.636557fa.js"><link rel="prefetch" href="/blog/vuepress/assets/js/59.5d1d0ce6.js"><link rel="prefetch" href="/blog/vuepress/assets/js/60.0b779f92.js"><link rel="prefetch" href="/blog/vuepress/assets/js/61.4ec3f2eb.js"><link rel="prefetch" href="/blog/vuepress/assets/js/62.8f70f114.js"><link rel="prefetch" href="/blog/vuepress/assets/js/64.c028fad5.js"><link rel="prefetch" href="/blog/vuepress/assets/js/66.73db652e.js"><link rel="prefetch" href="/blog/vuepress/assets/js/67.1a91446d.js"><link rel="prefetch" href="/blog/vuepress/assets/js/68.e5a12a42.js"><link rel="prefetch" href="/blog/vuepress/assets/js/69.6ddcb882.js"><link rel="prefetch" href="/blog/vuepress/assets/js/70.ceb70d85.js"><link rel="prefetch" href="/blog/vuepress/assets/js/71.a804ef40.js"><link rel="prefetch" href="/blog/vuepress/assets/js/73.2f28b842.js"><link rel="prefetch" href="/blog/vuepress/assets/js/74.571c2ab1.js"><link rel="prefetch" href="/blog/vuepress/assets/js/75.f365c2a1.js"><link rel="prefetch" href="/blog/vuepress/assets/js/76.0916a3cd.js"><link rel="prefetch" href="/blog/vuepress/assets/js/77.469aed17.js"><link rel="prefetch" href="/blog/vuepress/assets/js/78.02cdd59d.js"><link rel="prefetch" href="/blog/vuepress/assets/js/79.44d7f95c.js"><link rel="prefetch" href="/blog/vuepress/assets/js/80.4ca072f1.js"><link rel="prefetch" href="/blog/vuepress/assets/js/81.d9239a49.js"><link rel="prefetch" href="/blog/vuepress/assets/js/82.b09096b2.js"><link rel="prefetch" href="/blog/vuepress/assets/js/83.f4bc8a9b.js"><link rel="prefetch" href="/blog/vuepress/assets/js/84.1ffe6969.js"><link rel="prefetch" href="/blog/vuepress/assets/js/85.44e980f9.js"><link rel="prefetch" href="/blog/vuepress/assets/js/86.c8579ac0.js"><link rel="prefetch" href="/blog/vuepress/assets/js/87.cd49f324.js"><link rel="prefetch" href="/blog/vuepress/assets/js/88.3851b6ff.js"><link rel="prefetch" href="/blog/vuepress/assets/js/89.b05297be.js"><link rel="prefetch" href="/blog/vuepress/assets/js/90.c1e3263e.js"><link rel="prefetch" href="/blog/vuepress/assets/js/91.b493a1bb.js"><link rel="prefetch" href="/blog/vuepress/assets/js/92.80ab06fd.js"><link rel="prefetch" href="/blog/vuepress/assets/js/93.c6ca00b3.js"><link rel="prefetch" href="/blog/vuepress/assets/js/94.e993d310.js"><link rel="prefetch" href="/blog/vuepress/assets/js/95.8e19a7ed.js">
    <link rel="stylesheet" href="/blog/vuepress/assets/css/0.styles.d4f29607.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div><a href="/blog/vuepress/" class="home-link router-link-active"><img src="/blog/vuepress/hero.png" class="logo"><span class="site-name can-hide">
      Denzel
    </span></a><div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""><!----></div><nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/vuepress/js/" class="nav-link">JS</a></div><div class="nav-item"><a href="/blog/vuepress/css/" class="nav-link router-link-active">CSS</a></div><div class="nav-item"><a href="/blog/vuepress/html/" class="nav-link">HTML</a></div><div class="nav-item"><a href="/blog/vuepress/else/" class="nav-link">其他</a></div><div class="nav-item"><a href="/blog/vuepress/study/" class="nav-link">study</a></div><a href="https://github.com/xiaotianxia" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav></div></header><div class="sidebar-mask"></div><div class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/blog/vuepress/js/" class="nav-link">JS</a></div><div class="nav-item"><a href="/blog/vuepress/css/" class="nav-link router-link-active">CSS</a></div><div class="nav-item"><a href="/blog/vuepress/html/" class="nav-link">HTML</a></div><div class="nav-item"><a href="/blog/vuepress/else/" class="nav-link">其他</a></div><div class="nav-item"><a href="/blog/vuepress/study/" class="nav-link">study</a></div><a href="https://github.com/xiaotianxia" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path><polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></nav><ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>CSS</span><!----></p><ul class="sidebar-group-items"><li><a href="/blog/vuepress/css/" class="sidebar-link">目录</a></li><li><a href="/blog/vuepress/css/svg_path_animation.html" class="active sidebar-link">SVG轻松实现路径动画</a></li><li><a href="/blog/vuepress/css/clip_path.html" class="sidebar-link">CSS中的图像处理 —— clip-path</a></li><li><a href="/blog/vuepress/css/columns.html" class="sidebar-link">Columns —— CSS多栏布局</a></li><li><a href="/blog/vuepress/css/grid_layout.html" class="sidebar-link">Grid —— CSS网格布局初探</a></li><li><a href="/blog/vuepress/css/styled_switch.html" class="sidebar-link">radio和checkbox的自定义样式</a></li><li><a href="/blog/vuepress/css/use_of_checkbox.html" class="sidebar-link">checkbox的应用</a></li></ul></div></li></ul></div><div class="page"><div class="content"><h1 id="svg轻松实现路径动画"><a href="#svg轻松实现路径动画" aria-hidden="true" class="header-anchor">#</a> SVG轻松实现路径动画</h1><h2 id="前言"><a href="#前言" aria-hidden="true" class="header-anchor">#</a> 前言</h2><p>最近在学习SVG相关的内容，感叹SVG真的是太强大了。内容之多，根本不是一两篇文章能够涵盖的。所以决定还是找几个小点慢慢学习吧。</p><p>很多电商网站里，在加入购物车时都会有一个形象的动画，让宝贝以类似抛物线的轨迹飞进购物车，就像不要钱一样😂 。
像这样：</p><p><img src="http://pn4meizzc.bkt.clouddn.com/path006.gif" alt></p><p>实现这种效果可能有很多方法，但是用SVG可以快速简单的实现。今天我们一块学习一下这个方法。</p><h2 id="svg路径"><a href="#svg路径" aria-hidden="true" class="header-anchor">#</a> SVG路径</h2><p>SVG中最强大的元素莫过于path了，它可以描绘机会任意的2D图形。</p><p>一个简单的路径是这样婶儿的：</p><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>path</span> <span class="token attr-name">d</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>M10 10 L75 10 L75 75 Z<span class="token punctuation">&quot;</span></span> <span class="token punctuation">/&gt;</span></span>
</code></pre><p>还有稍微复杂的路径：</p><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>path</span> <span class="token attr-name">d</span><span class="token attr-value"><span class="token punctuation">=</span><span class="token punctuation">&quot;</span>M199.428,125.107C159.17,32.871,44.736,54.392,43.983,161.445c-0.417,58.8,54.491,80.773,91.049,104.277,35.45,22.8,60.68,53.978,64.634,67.252,3.385-13.006,31.486-45.071,64.3-67.889,35.88-24.951,91.466-45.485,91.049-104.279C354.26,53.487,237.835,36.55,199.428,125.107Z<span class="token punctuation">&quot;</span></span><span class="token punctuation">/&gt;</span></span>
</code></pre><p>这是一个心形，下面会用到这个路径。当然这种路径不是手动写出来的，而是用专门的软件导出的。这个就是我用PS导出来的。</p><p>path有以下这些指令：</p><table><thead><tr><th style="text-align:left">指令</th><th style="text-align:left">参数</th><th style="text-align:left">描述</th></tr></thead><tbody><tr><td style="text-align:left">M(Move to)</td><td style="text-align:left">x y</td><td style="text-align:left">起始点坐标x y</td></tr><tr><td style="text-align:left">L(Line to)</td><td style="text-align:left">x y</td><td style="text-align:left">从当前点的坐标画直线到指定点的 x y坐标</td></tr><tr><td style="text-align:left">H(Horizontal line to)</td><td style="text-align:left">x</td><td style="text-align:left">从当前点的坐标画水平直线到指定的x轴坐标</td></tr><tr><td style="text-align:left">V(Vertical line to)</td><td style="text-align:left">y</td><td style="text-align:left">从当前点的座标画垂直直线到指定的y轴坐标</td></tr><tr><td style="text-align:left">C(Curve)</td><td style="text-align:left">x1 y1 x2 y2 x y</td><td style="text-align:left">从当前点的坐标画条贝塞风线到指定点的x, y坐标，其中 x1 y1及x2, y2为控制点</td></tr><tr><td style="text-align:left">S(Smooth curve)</td><td style="text-align:left">x2 y2 x y</td><td style="text-align:left">从当前点的坐标画条反射的贝塞曲线到指定点的x, y坐标，其中x2, y2为反射的控制点</td></tr><tr><td style="text-align:left">Q(Quadratic Bézier curve)</td><td style="text-align:left">x1 y1 x y</td><td style="text-align:left">从当前点的坐标画条反射二次贝塞曲线到指定点的x, y坐标，其中x1 y1为控制点</td></tr><tr><td style="text-align:left">T(Smooth Quadratic Bézier curve)</td><td style="text-align:left">x y</td><td style="text-align:left">从当前点的坐标画条反射二次贝塞曲线到指定点的x, y坐标，以前一个坐标为反射控制点</td></tr><tr><td style="text-align:left">A(Arc)</td><td style="text-align:left">rx ry x-axis-rotation large-arc-flag sweep-flag x y</td><td style="text-align:left">从当前点的坐标画个椭圆形到指定点的x, y坐标，其中rx, ry为椭圆形的x轴及y轴的半径，x-axis-rotation是弧线与x轴的旋转角度，large-arc-flag则设定1最大角度的弧线或是0最小角度的弧线，sweep-flag设定方向为1顺时针方向或0逆时针方向</td></tr><tr><td style="text-align:left">Z(Closepath)</td><td style="text-align:left">无</td><td style="text-align:left">关闭路径，将当前点坐标与第一个点的坐标连接起来</td></tr></tbody></table><h2 id="offset-path、offset-distance"><a href="#offset-path、offset-distance" aria-hidden="true" class="header-anchor">#</a> offset-path、offset-distance</h2><p>两个都是CSS属性。</p><p><strong>offset-path</strong>表示元素的运动路径；</p><p><strong>offset-distance</strong>定义了元素在路径上运动的距离，单位是数值或百分比。</p><p>可想而知，用这两个属性就能实现路径动画了，只需改变offset-distance的值即可。</p><p>举一个栗子：</p><h3 id="demo-🌰"><a href="#demo-🌰" aria-hidden="true" class="header-anchor">#</a> demo 🌰</h3><div class="spreadown-wrapper" data-v-ba9b4902><div class="spreadown-content" data-v-ba9b4902><iframe height="480" scrolling="no" title="SVG-二次贝塞尔曲线" src="//codepen.io/_tianxia/embed/VBmBGY/?height=480&amp;theme-id=33504&amp;default-tab=css,result&amp;embed-version=2" frameborder="no" allowtransparency="true" allowfullscreen="allowfullscreen" style="width:100%;" data-v-ba9b4902>See the Pen <a href="https://codepen.io/_tianxia/pen/VBmBGY/" data-v-ba9b4902>SVG-二次贝塞尔曲线</a> by Denzel (<a href="https://codepen.io/_tianxia" data-v-ba9b4902>@_tianxia</a>) on <a href="https://codepen.io" data-v-ba9b4902>CodePen</a>.</iframe><div class="codepen-wrapper"><a href="https://codepen.io/_tianxia/pen/VBmBGY/" target="_blank" class="el-button el-button--primary is-plain">show in codepen <i class="el-icon-d-arrow-right"></i></a></div></div><div class="spreadown-trigger" data-v-ba9b4902><i class="el-icon-arrow-right" data-v-ba9b4902></i><span class="text" style="display:;" data-v-ba9b4902>点击展开</span><span class="text" style="display:none;" data-v-ba9b4902>点击隐藏</span></div></div><p>如果是心形的呢，我们让它40s之内转10圈，再来一个栗子：</p><h3 id="demo-🌰🌰"><a href="#demo-🌰🌰" aria-hidden="true" class="header-anchor">#</a> demo 🌰🌰</h3><div class="spreadown-wrapper" data-v-ba9b4902><div class="spreadown-content" data-v-ba9b4902><iframe height="410" scrolling="no" title="SVG &amp; CSS path" src="//codepen.io/_tianxia/embed/PBbwXd/?height=410&amp;theme-id=33504&amp;default-tab=css,result&amp;embed-version=2" frameborder="no" allowtransparency="true" allowfullscreen="allowfullscreen" style="width:100%;" data-v-ba9b4902>See the Pen <a href="https://codepen.io/_tianxia/pen/PBbwXd/" data-v-ba9b4902>SVG &amp; CSS path</a> by Denzel (<a href="https://codepen.io/_tianxia" data-v-ba9b4902>@_tianxia</a>) on <a href="https://codepen.io" data-v-ba9b4902>CodePen</a>.</iframe><div class="codepen-wrapper"><a href="https://codepen.io/_tianxia/pen/PBbwXd/" target="_blank" class="el-button el-button--primary is-plain">show in codepen <i class="el-icon-d-arrow-right"></i></a></div></div><div class="spreadown-trigger" data-v-ba9b4902><i class="el-icon-arrow-right" data-v-ba9b4902></i><span class="text" style="display:;" data-v-ba9b4902>点击展开</span><span class="text" style="display:none;" data-v-ba9b4902>点击隐藏</span></div></div><h2 id="贝塞尔曲线"><a href="#贝塞尔曲线" aria-hidden="true" class="header-anchor">#</a> 贝塞尔曲线</h2><p>那怎么模拟出抛物线的形状呢？这里想到了贝塞尔曲线，因为path可以很轻松的绘制贝塞尔曲线。
对于贝塞尔曲线其实我不是太了解，只是看着这种曲线就觉得很“性感”，而且貌似阶数越高越是<strong>性感</strong>😊。</p><p>如下面俩图：</p><p><img src="http://pn4meizzc.bkt.clouddn.com/path005.gif" alt="small demo"><img src="http://pn4meizzc.bkt.clouddn.com/path003.gif" alt="small demo"></p><p>同学们可以自行感受下，
<div class="spreadown-wrapper" data-v-ba9b4902><div class="spreadown-content" data-v-ba9b4902><div class="iframe-wrapper" style="height:720px;"><iframe src="https://myst729.github.io/bezier-curve/?_=1550502593199" frameborder="0"></iframe></div></div><div class="spreadown-trigger" data-v-ba9b4902><i class="el-icon-arrow-right" data-v-ba9b4902></i><span class="text" style="display:;" data-v-ba9b4902>点击展开</span><span class="text" style="display:none;" data-v-ba9b4902>点击隐藏</span></div></div>
挂了？！那就点击<a href="https://myst729.github.io/bezier-curve/" target="_blank" rel="noopener noreferrer">这里</a>自行前往。</p><p>于是我们可以用一个二阶贝塞尔曲线来模拟抛物线的轨迹：我们暂定三个点分别在<strong>左下角</strong>、<strong>上中间</strong>和<strong>左中间</strong>。</p><p>这样：</p><p><img src="http://pn4meizzc.bkt.clouddn.com/blogpath.gif" alt></p><p>只要在页面上获取到这三个点，就可以了。</p><p>又一个栗子：</p><h3 id="demo-🌰🌰🌰"><a href="#demo-🌰🌰🌰" aria-hidden="true" class="header-anchor">#</a> demo 🌰🌰🌰</h3><div class="spreadown-wrapper" data-v-ba9b4902><div class="spreadown-content" data-v-ba9b4902><iframe height="440" scrolling="no" title="SVG-动态贝塞尔曲线" src="//codepen.io/_tianxia/embed/MBbqGM/?height=440&amp;theme-id=33504&amp;default-tab=js,result&amp;embed-version=2" frameborder="no" allowtransparency="true" allowfullscreen="allowfullscreen" style="width:100%;" data-v-ba9b4902>See the Pen <a href="https://codepen.io/_tianxia/pen/MBbqGM/" data-v-ba9b4902>SVG-动态贝塞尔曲线</a> by Denzel (<a href="https://codepen.io/_tianxia" data-v-ba9b4902>@_tianxia</a>) on <a href="https://codepen.io" data-v-ba9b4902>CodePen</a>.</iframe><div class="codepen-wrapper"><a href="https://codepen.io/_tianxia/pen/MBbqGM/" target="_blank" class="el-button el-button--primary is-plain">show in codepen <i class="el-icon-d-arrow-right"></i></a></div></div><div class="spreadown-trigger" data-v-ba9b4902><i class="el-icon-arrow-right" data-v-ba9b4902></i><span class="text" style="display:;" data-v-ba9b4902>点击展开</span><span class="text" style="display:none;" data-v-ba9b4902>点击隐藏</span></div></div><p>继续添加上按钮，加点图片，就是这样的：</p><h3 id="demo-🌰🌰🌰🌰"><a href="#demo-🌰🌰🌰🌰" aria-hidden="true" class="header-anchor">#</a> demo 🌰🌰🌰🌰</h3><div class="spreadown-wrapper" data-v-ba9b4902><div class="spreadown-content" data-v-ba9b4902><iframe height="564" scrolling="no" title="SVG-路径动画" src="//codepen.io/_tianxia/embed/djOwyY/?height=564&amp;theme-id=33504&amp;default-tab=js,result&amp;embed-version=2" frameborder="no" allowtransparency="true" allowfullscreen="allowfullscreen" style="width:100%;" data-v-ba9b4902>See the Pen <a href="https://codepen.io/_tianxia/pen/djOwyY/" data-v-ba9b4902>SVG-路径动画</a> by Denzel (<a href="https://codepen.io/_tianxia" data-v-ba9b4902>@_tianxia</a>) on <a href="https://codepen.io" data-v-ba9b4902>CodePen</a>.</iframe><div class="codepen-wrapper"><a href="https://codepen.io/_tianxia/pen/djOwyY/" target="_blank" class="el-button el-button--primary is-plain">show in codepen <i class="el-icon-d-arrow-right"></i></a></div></div><div class="spreadown-trigger" data-v-ba9b4902><i class="el-icon-arrow-right" data-v-ba9b4902></i><span class="text" style="display:;" data-v-ba9b4902>点击展开</span><span class="text" style="display:none;" data-v-ba9b4902>点击隐藏</span></div></div><h2 id="总结"><a href="#总结" aria-hidden="true" class="header-anchor">#</a> 总结</h2><p>遗憾的是，目前<a href="https://caniuse.com/#search=offset-path" target="_blank" rel="noopener noreferrer">只有Chrome和部分移动端浏览器（如安卓版UC和三星）</a>支持offset-path属性😰。</p><p>除此之外，还有三个相关属性：<a href="https://www.w3.org/TR/motion-1/#offset-anchor-property" target="_blank" rel="noopener noreferrer">offset-ancor</a>、<a href="https://www.w3.org/TR/motion-1/#offset-rotate-property" target="_blank" rel="noopener noreferrer">offset-rotate</a>和<a href="https://www.w3.org/TR/motion-1/#offset-position-property" target="_blank" rel="noopener noreferrer">offset-position</a>
分别表示锚定的中心点、运动的角度和路径的初始位置，感兴趣的同学可自行前往学习。</p><h2 id="参考资料"><a href="#参考资料" aria-hidden="true" class="header-anchor">#</a> 参考资料</h2><ul><li><a href="https://www.w3.org/TR/motion-1/" target="_blank" rel="noopener noreferrer">Motion Path Module Level 1</a></li><li><a href="http://www.w3cplus.com/svg/svg-animation-guide.html" target="_blank" rel="noopener noreferrer">SVG 路径动画简易指南</a></li><li><a href="https://myst729.github.io/bezier-curve/" target="_blank" rel="noopener noreferrer">Bézier Curve</a></li><li><a href="http://cubic-bezier.com/#.17,.67,.83,.67" target="_blank" rel="noopener noreferrer">http://cubic-bezier.com</a></li></ul></div><div class="wx-wrapper" data-v-0de8a4bf><p class="wx-txt" data-v-0de8a4bf>欢迎关注</p><img src="http://pn4meizzc.bkt.clouddn.com/wxqr.png" class="wx-img" data-v-0de8a4bf></div><div class="beg-wrapper" data-v-1f1af99c><a href="javascript:;" class="btn show" data-v-1f1af99c><img src="http://pn4meizzc.bkt.clouddn.com/blogshang_log.png" data-v-1f1af99c></a><p class="shang-txt" data-v-1f1af99c>赏不赏，看您心情</p><img src="http://pn4meizzc.bkt.clouddn.com/blogWechatIMG35.jpeg" class="shangImg" data-v-1f1af99c></div><!----><div class="content page-nav"><p class="inner"><span class="prev">
        ← <a href="/blog/vuepress/css/" class="prev router-link-active">
          目录
        </a></span><span class="next"><a href="/blog/vuepress/css/clip_path.html">
          CSS中的图像处理 —— clip-path
        </a> →
      </span></p></div></div></div></div>
    <script src="/blog/vuepress/assets/js/48.e0bf8b54.js" defer></script><script src="/blog/vuepress/assets/js/63.9ac2b61d.js" defer></script><script src="/blog/vuepress/assets/js/65.923a8d15.js" defer></script><script src="/blog/vuepress/assets/js/72.f1c4098c.js" defer></script><script src="/blog/vuepress/assets/js/app.15770e34.js" defer></script>
  </body>
</html>
